<?php

namespace app\common\exception;

use support\exception\BusinessException;
use Webman\Http\Request;
use Webman\Http\Response;

class ApiException extends BusinessException
{
    public function render(Request $request): ?Response
    {
        return json(['code' => $this->getCode() !== null ? $this->getCode() : 0, 'msg' => $this->getMessage()]);
        // var_dump($request->expectsJson());
        // if ($request->expectsJson()) {
        //     echo 123;
        //     return json(['code' => $this->getCode() !== null ? $this->getCode() : 0, 'msg' => $this->getMessage()]);
        // }
        //     echo 123;
        // return new Response(200, [], $this->getMessage());
    }
}